﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using DLULearningNetworkModel;
using DLULearningNetwork.Libs;

namespace DLULearningNetwork
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class LNService
    {
        [OperationContract]
        public Account GetLoginUser()
        {
            Account result = new Account();
            Account account = (Account)LibSession.Get(Constants.ACCOUNT_LOGIN);
            result.AccountID_u = account.AccountID_u;
            result.FirstName_s = account.FirstName_s;
            result.LastName_s = account.LastName_s;
            result.Email_s = account.Email_s;
            result.Sex_b = account.Sex_b;
            result.DateOfBirth_dt = account.DateOfBirth_dt;
            result.Password_s = account.Password_s;
            result.Nickname_s = account.Nickname_s;
            result.SecurityQuestionID_u = account.SecurityQuestionID_u;
            result.Answer_s = account.Answer_s;
            result.Avatar_s = account.Avatar_s;
            return result;            
        }

        [OperationContract]
        public bool CheckIsCourseOwner(Guid accountID, Guid courseID)
        {
            return (Course.Single(accountID, courseID) != null);
        }       
    }
}
